<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib uri="/WEB-INF/page-base.tld" prefix="w"%>

<%String path=request.getContextPath(); %>
<style>
	.itemul{margin:0px;text-align:left;background:#fff;padding:0px;border:1px solid #E4E4E4;border-radius:2px;width:300px;height:180px;overflow: auto}
	.itemul li{padding:3px 12px;margin:1px;cursor:default;position: relative;list-style:none;}
	.itemul li i{position: absolute;right:8px;top:10px;width:8px; height:8px; border-left: 1px solid #D1D1D1; border-top: 1px solid #D1D1D1; transform: rotate(135deg); -webkit-transform: rotate(135deg);}
	.itemul li:hover{background-color:#EEEEEE}
	.itemul li.cur{background-color:#DDE6EF;color:#EA8010}
</style>
<script>
	function selmodelattr(obj,radio){
		var par=$(obj).parent();
		if(radio)$("li",par).removeClass("cur");
		if(obj.className=='cur')obj.className='';
		else obj.className='cur';
	}
	function addModelAttr(){
		window.parent.$w.openDialog({url:ctx+"/products/ProductClassPage@showModelAttrAdd.page?bean.classCode="+$getByName("bean.classcode").val()+"&bean.tag=2&bean.type=2",title:'添加商品属性',w:600,h:220,afterClose:function(json){
			if(json){
				var data=$.parseJSON(json);
				$("#modelattrL").append('<li id="L'+data.id+'" onclick="selmodelattr(this,true);loadattrItem(this)">'+data.name+'<i></i></li>')
			}
		}});
	}
	function editModelAttr(){
		var attrid=$("#modelattrL li.cur").attr("id");
		if(attrid){
			window.parent.$w.openDialog({url:ctx+"/products/ProductClassPage@showModelAttrAdd.page?bean.id="+attrid.replace("L",""),title:'编辑商品属性',w:600,h:220,afterClose:function(json){
				if(json){
					var data=$.parseJSON(json);
					$('#'+attrid).text(data.name);
				}
			}});
		}
	}
	function delModelAttr(){
		var attrid=$("#modelattrL li.cur").attr("id");
		if(attrid){
			window.parent.$w.confirmMsg("确定删除？", function(r){
				if(r){
					$w.doUrl(ctx+"/products/ProductClassPage@delModelAttr.page?bean.id="+attrid.replace("L",""),{},function(json){
						if(json){$('#'+attrid).remove();$("#modelattrR").html('');}
					})
				}
			})
		}
	}
	
	function loadattrItem(obj){
		$("#modelattrR").html('');
		$w.doUrl(ctx+"/products/ProductClassPage@loadModelAttrItem.page?bean.attrid="+obj.id.replace("L",""),{},function(json){
			$("#modelattrR").html('');
			$(json.items).each(function(){
				$("#modelattrR").append('<li id="'+this.id+'" onclick="selmodelattr(this);">'+this.text+'</li>')
			})
		})
	}
	function addModelAttrItem(){
		var attrid=$("#modelattrL li.cur").attr("id");
		if(attrid){
			window.parent.$w.openDialog({url:ctx+"/products/ProductClassPage@showModelAttrItemAdd.page?bean.attrid="+attrid.replace("L",""),title:'添加商品属性值',w:600,h:220,afterClose:function(json){
				if(json){
					var data=$.parseJSON(json);
					$("#modelattrR").append('<li id="'+data.id+'" onclick="selmodelattr(this);">'+data.text+'</li>')
				}
			}});
		}
	}
	function editModelAttrItem(){
		if($("#modelattrR li.cur").length>0){
			var attrid=$("#modelattrR li.cur").eq(0).attr("id");
			if(attrid){
				window.parent.$w.openDialog({url:ctx+"/products/ProductClassPage@showModelAttrItemAdd.page?bean.id="+attrid,title:'编辑商品属性值',w:600,h:220,afterClose:function(json){
					if(json){
						var data=$.parseJSON(json);
						$('#'+attrid).text(data.text);
					}
				}});
			}
		}
	}
	function delModelAttrItem(){
		var ids="";
		$("#modelattrR li.cur").each(function(){
			if(ids!="")ids+=",";
			ids+=this.id;
		})
		if(ids){
			window.parent.$w.confirmMsg("确定删除？", function(r){
				if(r){
					$w.doUrl(ctx+"/products/ProductClassPage@delModelAttrItem.page?bean.ids="+ids,{},function(json){
						if(json){
							$("#modelattrR li.cur").remove();
						}
					})
				}
			})
		}
	}
	
	
	function addModelAttr_s(){
		window.parent.$w.openDialog({url:ctx+"/products/ProductClassPage@showModelAttrAdd.page?bean.classCode="+$getByName("bean.classcode").val()+"&bean.tag=3&bean.type=3",title:'添加销售属性',w:600,h:220,afterClose:function(json){
			if(json){
				var data=$.parseJSON(json);
				$("#modelattrL_s").append('<li id="L'+data.id+'" onclick="selmodelattr(this,true);loadattrItem_s(this)">'+data.name+'<i></i></li>')
			}
		}});
	}
	function editModelAttr_s(){
		var attrid=$("#modelattrL_s li.cur").attr("id");
		if(attrid){
			window.parent.$w.openDialog({url:ctx+"/products/ProductClassPage@showModelAttrAdd.page?bean.id="+attrid.replace("L",""),title:'编辑销售属性',w:600,h:220,afterClose:function(json){
				if(json){
					var data=$.parseJSON(json);
					$('#'+attrid).text(data.name);
				}
			}});
		}
	}
	function delModelAttrItem_s(){
		var attrid=$("#modelattrR_s li.cur").attr("id");
		if(attrid){
			window.parent.$w.confirmMsg("确定删除？", function(r){
				if(r){
					$w.doUrl(ctx+"/products/ProductClassPage@delModelAttr.page?bean.id="+attrid.replace("L",""),{},function(json){
						if(json)$('#'+attrid).remove();
					})
				}
			})
		}
	}
	
	function loadattrItem_s(obj){
		$("#modelattrR_s").html('');
		$w.doUrl(ctx+"/products/ProductClassPage@loadModelAttrItem.page?bean.attrid="+obj.id.replace("L",""),{},function(json){
			$("#modelattrR_s").html('');
			$(json.items).each(function(){
				$("#modelattrR_s").append('<li id="'+this.id+'" onclick="selmodelattr(this);">'+this.text+'</li>')
			})
		})
	}
	function addModelAttrItem_s(){
		var attrid=$("#modelattrL_s li.cur").attr("id");
		if(attrid){
			window.parent.$w.openDialog({url:ctx+"/products/ProductClassPage@showModelAttrItemAdd.page?bean.attrid="+attrid.replace("L",""),title:'添加销售属性值',w:600,h:220,afterClose:function(json){
				if(json){
					var data=$.parseJSON(json);
					$("#modelattrR_s").append('<li id="'+data.id+'" onclick="selmodelattr(this);">'+data.text+'</li>')
				}
			}});
		}
	}
	function editModelAttrItem_s(){
		if($("#modelattrR_s li.cur").length>0){
			var attrid=$("#modelattrR_s li.cur").eq(0).attr("id");
			if(attrid){
				window.parent.$w.openDialog({url:ctx+"/products/ProductClassPage@showModelAttrItemAdd.page?bean.id="+attrid,title:'编辑销售属性值',w:600,h:220,afterClose:function(json){
					if(json){
						var data=$.parseJSON(json);
						$('#'+attrid).text(data.text);
					}
				}});
			}
		}
	}
	function delModelAttr_s(){
		var attrid=$("#modelattrL_s li.cur").attr("id");
		if(attrid){
			window.parent.$w.confirmMsg("确定删除？", function(r){
				if(r){
					$w.doUrl(ctx+"/products/ProductClassPage@delModelAttr.page?bean.id="+attrid.replace("L",""),{},function(json){
						if(json){$('#'+attrid).remove();$("#modelattrR_s").html('');}
					})
				}
			})
		}
	}
	
</script>

<div class="easyui-panel" data-options="doSize:false,layoutH:10,border:false" style="margin:5px">
	<form method="post" action="" class="pageForm">
		<w:hidden bind="bean.classcode"/>
		<div class="ui-formContent" style="padding:5px 20px 20px 20px;">
			<div class="headT"><span></span><label>商品属性</label></div>
			<div style="border:1px solid #DDDDDD;border-radius:3px;width:700px;padding:20px">
				<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td width="50%" valign="top">
						<p>属性名称</p>
						<ul class="itemul" id="modelattrL">
							<w:iterate id="info" bind="#attrs">
								<li id="L<w:write bind="#info.id"/>" onclick="selmodelattr(this,true);loadattrItem(this)"><w:write bind="#info.name"/><i></i></li>
							</w:iterate>
						</ul>
						<div style="margin-top:8px;">
							<a href="javascript:void(0);" class="ui_btn marginR8" onclick="addModelAttr()">新增属性</a><a href="javascript:void(0);" class="ui_btn marginR8" onclick="editModelAttr()">编辑属性</a><a href="javascript:void(0);" class="ui_btn marginR8" onclick="delModelAttr()">删除属性</a>
						</div>
					</td>
					<td width="50%" valign="top" style="text-align:right">
						<p style="text-align:left">属性值</p>
						<ul class="itemul" id="modelattrR">
							
						</ul>
						<div style="margin-top:8px;text-align:left">
							<a href="javascript:void(0);" class="ui_btn marginR8" onclick="addModelAttrItem()">新增属性</a><a href="javascript:void(0);" class="ui_btn marginR8" onclick="editModelAttrItem()">编辑属性</a><a href="javascript:void(0);" class="ui_btn marginR8" onclick="delModelAttrItem()">删除属性</a>
						</div>
					</td>
				</tr>
				</table>
			</div>
			<div style="height:20px;width:100%;"></div>
			<div class="headT"><span></span><label>销售属性</label></div>
			<div style="border:1px solid #DDDDDD;border-radius:3px;width:700px;padding:20px">
				<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td width="50%" valign="top">
						<p>属性名称</p>
						<ul class="itemul" id="modelattrL_s">
							<w:iterate id="info" bind="#saleattrs">
								<li id="L<w:write bind="#info.id"/>" onclick="selmodelattr(this,true);loadattrItem_s(this)"><w:write bind="#info.name"/><i></i></li>
							</w:iterate>
						</ul>
						<div style="margin-top:8px;">
							<a href="javascript:void(0);" class="ui_btn marginR8" onclick="addModelAttr_s()">新增属性</a><a href="javascript:void(0);" class="ui_btn marginR8" onclick="editModelAttr_s()">编辑属性</a><a href="javascript:void(0);" class="ui_btn marginR8" onclick="delModelAttr_s()">删除属性</a>
						</div>
					</td>
					<td width="50%" valign="top" style="text-align:right">
						<p style="text-align:left">属性值</p>
						<ul class="itemul" id="modelattrR_s">
							
						</ul>
						<div style="margin-top:8px;text-align:left">
							<a href="javascript:void(0);" class="ui_btn marginR8" onclick="addModelAttrItem_s()">新增属性</a><a href="javascript:void(0);" class="ui_btn marginR8" onclick="editModelAttrItem_s()">编辑属性</a><a href="javascript:void(0);" class="ui_btn marginR8" onclick="delModelAttrItem_s()">删除属性</a>
						</div>
					</td>
				</tr>
				</table>
			</div>
		</div>
	</form>
</div>
